package com.itheima.jdbc;

import java.sql.*;

public class JDBCDemo1 {
    public static void main(String[] args) throws ClassNotFoundException, SQLException {
        //注册驱动
        Class.forName("com.mysql.jdbc.Driver");
        //获取连接,需要url,用户名,密码
        Connection con = DriverManager.getConnection("jdbc:mysql:///db9", "root", "005816");
        //获取执行sql的对象,负责CRUD
        Statement statement = con.createStatement();
        //执行查询操作,获取结果
        ResultSet rs = statement.executeQuery("select * from student ");
        //打印结果
        while (rs.next()){//如果返回true则代表下一行有值
            int id = rs.getInt("id");
            String name = rs.getString("name");
            int age = rs.getInt("age");
            int score = rs.getInt("score");
            System.out.println(id+","+name+","+age+","+score);
        }
        //释放资源
        rs.close();
        statement.close();
        con.close();
    }
}